<?php
/*error_reporting(E_ALL);
ini_set("display_errors", 1);*/

require_once '../../includefiles.php';
require_once '../../model/state.php';

$stateObj = new Model_State();
	
/*function postCode2Geog($code){
 $code = strtolower(str_replace(' ','',$code));
 $uri = "http://www.streetmap.co.uk/streetmap.dll?GridConvert?name=".$code."&type=Postcode";
 
 $ch = curl_init($uri);
 curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 $output = curl_exec($ch);
 curl_close($ch);
 
 preg_match('#long</strong> \(wgs84\)\s*?\<\/td\>\s*?\<td width="50%" align="center" valign="middle"\>\S{2,3}:\S{2}:\S{2} \( (.*?) \)#i',$output,$longMatch);
 preg_match('#lat</strong> \(wgs84\)\s*?\<\/td\>\s*?\<td width="50%" align="center" valign="middle"\>\S{2,3}:\S{2}:\S{2} \( (.*?) \)#i',$output,$latMatch);
 $long = $longMatch[1];
 $lat = $latMatch[1];
 
 return array($lat,$long);
}	
function getLatLong($code){
 $mapsApiKey = 'AIzaSyDdttY53OplH9vGSM9waT-lXkDGu6ocCnA';
 $query = "http://maps.google.co.uk/maps/geo?q=".urlencode($code)."&output=json&key=".$mapsApiKey;
 $data = file_get_contents($query);
 // if data returned
 if($data){
  // convert into readable format
  $data = json_decode($data);
  $long = $data->Placemark[0]->Point->coordinates[0];
  $lat = $data->Placemark[0]->Point->coordinates[1];
  return array('Latitude'=>$lat,'Longitude'=>$long);
 }else{
  return false;
 }
}
*/

if($_GET['google_address'])
{
	$postalcode = $_GET['google_address']; 
	$getpostalcodedetail = $stateObj->getPostalDetailsByPostalCode($postalcode);
}
//print_R($getpostalcodedetail);die();

if($_GET['radius'])
{
	$getradius = $_GET['radius']; 
	$Meterconvert = $getradius;
	$smarty->assign("Meterconvert", $Meterconvert);

}

if($dynamicaddress=='')
{
	$smarty->assign("geog1", -27);
	$smarty->assign("geog2", 133);
}
else
{
	$smarty->assign("geog1", $getpostalcodedetail['lat']);
	$smarty->assign("geog2", $getpostalcodedetail['lon']);
}

$smarty->display(TEMPLATEDIR.'modules/register/google_map.tpl');	
?>
